<?php
	include "../../public/commom/config.php";
	include "../lock1.php";
	include "../../public/commom/commom.php";
	include "../../public/commom/function.php";
	
	if($_POST) {
		$id = $_POST["id"];
		$pos = $_POST["pos"];
		$rul = $_POST["rul"];
		$img = $_POST["pimg"];
		
		if($_FILES) {
			//图片
			$imgsrc = $_FILES["img"]["tmp_name"];//获取图片临时路径
			$fname = $_FILES["img"]["name"];//获取图片名称
			$a = explode(".", $fname);//获取图片后缀名
			$ext = array_pop($a);//
			$dst = $uploadPath . time().mt_rand(). "." . $ext;//随机生成图片名称
			
			$gimg = $_GET["img"];
			$isrc = $uploadPath . $img;
			$tsrc = $uploadPathThumb . $img;
			
			//图片上传成功
			if(move_uploaded_file($imgsrc, $dst)) {
				unlink($isrc);
				unlink($tsrc);
				
				thumb($dst, 200, 200);//生成缩略图
				
				$img = basename($dst);//获取带后缀名的图片名称
			}
		}
	
		$sql = "UPDATE advert SET img = '$img', pos = '$pos', rul = '$rul' WHERE id = $id";
			
		$result = mysqli_query($conn, $sql);
		
		mysqli_close($conn);
			
		header("Location: ./index.php");
	}
?>